@import './theme/default';
@import './theme/font';

@mixin caret($pos) {
  @include theme-color(border-#{$pos}-color, stroke, 3);
  width: 0;
  height: 0;
  border-left: 4.5px solid transparent;
  border-right: 4.5px solid transparent;
  border-#{$pos}-width: 6px;
  border-#{$pos}-style: solid;
  position: absolute;
}

.zent-grid {
  @include theme-color(color, stroke, 1);
  font-size: $font-size-normal;
  position: relative;
  line-height: 1.5;
  overflow: hidden;

  &.zent-grid-scroll-position-left {
    .zent-grid-fixed-left {
      box-shadow: none;
    }
  }

  &.zent-grid-scroll-position-right {
    .zent-grid-fixed-right {
      box-shadow: none;
    }
  }

  &-table {
    width: 100%;
    text-align: left;
    border-collapse: collapse;
    border-spacing: 0;

    &-ellipsis {
      table-layout: fixed;

      .zent-grid-nowrap {
        overflow: hidden;
        text-overflow: ellipsis;
      }
    }
  }

  &-bordered {
    table {
      border-collapse: collapse;
    }

    th,
    td {
      @include theme-color(border-color, stroke, 6);
      border-width: 1px;
      border-style: solid;
      border-top: 0;

      &:first-child {
        border-left: 0;
      }

      &:last-child {
        border-right: 0;
      }
    }
  }

  &-text-align-left {
    text-align: left;
  }

  &-text-align-right {
    text-align: right;

    .zent-grid-thead-sort {
      margin-right: 16px;
    }
  }

  &-text-align-center {
    text-align: center;
  }

  &-nowrap {
    white-space: nowrap;
    word-break: keep-all;
  }

  &-thead {
    .caret-up {
      @include caret(bottom);
      top: 2px;
      left: 6px;
    }

    .caret-down {
      @include caret(top);
      bottom: 1px;
      left: 6px;
    }

    &-sort {
      position: relative;

      &-btn {
        cursor: pointer;
      }
    }

    &-sort-desc,
    &-sort-asc {
      cursor: pointer;
    }

    &-sort-desc {
      .caret-down {
        @include theme-color(border-top-color, primary, 4);
      }
    }

    &-sort-asc {
      .caret-up {
        @include theme-color(border-bottom-color, primary, 4);
      }
    }
  }

  &-thead > tr > th {
    &[colspan] {
      text-align: center;
    }
  }

  &-fixed {
    width: auto;
  }

  &-fixed-left,
  &-fixed-right {
    position: absolute;
    top: 0;
    overflow: hidden;

    .zent-grid-fixed {
      border-left: 0;
      border-right: 0;
    }
  }

  &-fixed-left {
    left: 0;
    // FIXME: 为了让fix住的部分底部阴影去除
    @include theme-shadow(focus);

    .zent-grid-header .zent-grid-table {
      border-right: 0;
    }

    .zent-grid-body {
      margin-right: -20px;
      box-sizing: border-box;
      margin-bottom: -15px;
      overflow: scroll;
    }

    table {
      width: auto;
    }
  }

  &-fixed-right {
    right: 0;
    // FIXME: 为了让fix住的部分底部阴影去除
    @include theme-shadow(focus);

    .zent-grid-header .zent-grid-table {
      border-left: 0;
    }

    .zent-grid-body .zent-grid-table {
      border-left: 0;
    }

    .zent-grid-body {
      box-sizing: border-box;
      margin-bottom: -15px;
      overflow: scroll;
    }
  }

  &-scroll {
    overflow: auto;

    table {
      width: auto;
      min-width: 100%;
    }

    .zent-grid-header {
      overflow-x: scroll;
      margin-bottom: -15px;
      padding-bottom: 15px;
    }

    .zent-grid-body {
      position: relative;
    }
  }

  &-empty {
    @include theme-color(border-bottom-color, stroke, 6);
    text-align: center;
    height: 50px;
    line-height: 50px;
    border-bottom-width: 1px;
    border-bottom-style: solid;
  }

  &-tr {
    @include theme-color(background-color, stroke, 9);
    display: table-row;
    height: 56px;

    &:hover,
    &__mouseover {
      @include theme-color(background-color, primary, 8);
    }

    &__expanded {
      td {
        @include theme-color(background-color, stroke, 8);
        padding: 10px 12px;
        word-break: break-all;
      }
    }
  }

  &-tr__disable-highlight {
    &:hover {
      @include theme-color(background-color, stroke, 9);
    }
  }

  &-th,
  &-td {
    @include theme-color(border-bottom-color, stroke, 6);
    font-size: $font-size-normal;
    display: table-cell;
    box-sizing: border-box;
    border-bottom-width: 1px;
    border-bottom-style: solid;
    vertical-align: middle;

    &:first-child {
      padding: 10px 12px;
    }

    &:last-child {
      padding: 10px 12px;
    }
  }

  &-th {
    @include theme-color(background-color, stroke, 8);
    line-height: 20px;
    padding: 10px 12px;
    font-weight: 500;
  }

  &-th.zent-grid-th-selection,
  &-td.zent-grid-td-selection,
  &-th.zent-grid-th-expand,
  &-td.zent-grid-td-expand {
    padding-right: 0;
  }

  &-td {
    line-height: 20px;
    padding: 10px 12px;
    position: relative;

    .zent-grid-expandable-btn {
      @include theme-color(border-color, stroke, 6);
      @include theme-color(background-color, stroke, 9);
      cursor: pointer;
      display: inline-block;
      width: 14px;
      height: 14px;
      text-align: center;
      line-height: 12px;
      border-width: 1px;
      border-style: solid;
      user-select: none;

      &.zent-grid-expand-btn::after {
        content: '+';
        box-sizing: border-box;
        width: 8px;
        display: inline-block;
      }

      &.zent-grid-collapse-btn::after {
        content: '-';
        box-sizing: border-box;
        width: 8px;
        display: inline-block;
      }
    }

    &-multiple-row {
      @include theme-color(border-color, stroke, 6);
      border-left-width: 1px;
      border-right-width: 1px;
      border-style: solid;
    }
  }

  &-tfoot {
    margin-top: 16px;
    overflow: hidden;

    .zent-grid-tfoot-page {
      margin-top: 0;
    }

    .zent-grid-batch.zent-grid-batch--fixed {
      @include theme-color(background-color, stroke, 9);
      @include theme-color(border-color, stroke, 6);
      position: fixed;
      left: unset;
      z-index: 1;
      bottom: 0;
      padding-top: 12px;
      box-sizing: border-box;
      border-top-width: 1px;
      border-top-style: solid;
    }
  }

  &-tfoot-page {
    margin-top: 10px;
    float: right;
  }

  a {
    @include theme-color(color, primary, 4);
    cursor: pointer;
  }

  .zent-grid-batch {
    padding-left: 12px;
    padding-bottom: 12px;
    display: flex;
    align-items: center;

    .batch-component {
      line-height: 20px;
      margin-right: 8px;

      &:last-child {
        margin-right: 0;
      }
    }
  }

  .zent-grid-batch__foot {
    float: left;
  }

  &-selection-checkbox {
    position: absolute;
    top: 50%;
    transform: translate(0, -50%);
    line-height: 1;
    font-size: 0;
    display: inline-block;
    margin-top: -1px;
  }

  .zent-grid-sticky-header {
    overflow-x: scroll;
  }

  .zent-grid-sticky-header-warp {
    position: absolute;
  }
}
